<?php
/**
* 支付宝读取csv文件
* @author ldward
* @date 2018.10.16
* @copyright leemanpaper.com
*/

require_once ('/data/www/oms/alipay3.3/AopSdk.php');
require_once ('/data/www/oms/custom/lib/pclzip.lib.php');  

try
{
    header("Content-type: text/html; charset=utf-8");
	date_default_timezone_set("PRC");

    $fileurl=$_POST['fileurl'];
    //$fileurl="/data/www/oms/download/20881213102235930156_201809/20881213102235930156_201809_业务明细_1.csv";
    $fileurl = iconv ( 'UTF-8', 'GBK', $fileurl );//中文linux特意转码下   

    $fp = fopen($fileurl, 'r') or die("can't open file"); 
    $res=array();
    $linenumber=0;
    while($csv_line = fgetcsv($fp))
    { 
        //跳过前五行，直接到支付宝提示及抬头数据
        if($linenumber<5)
        {
            $linenumber++;
            continue;
        }
        $resline[] = array();
        for($i=0, $j=count($csv_line); $i<$j; $i++)
        {  
            $resline[$i]=htmlentities(iconv("gb2312","utf-8",$csv_line[$i])); 
        } 
        $res[]=$resline;
        unset($resline);
    } 
    echo json_encode($res);
    fclose($fp) or die("can't close file");
}catch (Exception $e) 
{
    echo $e->getMessage();
}
